package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
/**
 * Created by Administrator on 2018/5/28.
 */
public class UserServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req,
                         HttpServletResponse resp)
            //ctrl +x删除
            //shift+enter换行
            throws ServletException, IOException {
        resp.setHeader("content-type","text/html;charset=UTF-8");
        PrintWriter out=resp.getWriter();
//        out.write("<table>\n" +
//                "    <tr>\n" +
//                "        <td>编码</td>\n" +
//                "        <td>用户名</td>\n" +
//                "        <td>密码</td>\n" +
//                "        <td>操作1</td>\n" +
//                "        <td>操作2</td>\n" +
//                "    </tr>\n" +
//                "    <tr>\n" +
//                "        <td>110</td>\n" +
//                "        <td>wenwen</td>\n" +
//                "        <td>123456</td>\n" +
//                "        <td>删除</td>\n" +
//                "        <td>更新</td>\n" +
//                "    </tr>\n" +
//                "\n" +
//                "</table>");
                //1.查数据库并且得到userList
               Database database=new Database();
        List<User> userList=database.getUserList();
        //2.request空间中新建一个名为userList的变量
        req.setAttribute("userList",userList);
        //3.跳转到userLIst.jsp页面
          req.getRequestDispatcher("/userList.jsp")
               .forward(req,resp);
    }
}
